#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main()
{
    int n = 0;
    while (scanf("%d", &n) != EOF)
    {
        int arr[] = { 0 };
        int i = 0;
        for (i = 0; i < n; i++)
        {
            scanf("%d", &arr[i]);
        }
        int k = 2;
        
        int tmp = 0;
        tmp = arr[0];
        int j = 0;
        while (k)
        {
            for (j = 0; j < n - 1; j++)
            {
                arr[j] = arr[j + 1];
            }
            arr[0] = arr[n - 1];
            arr[n - 1] = tmp;
            k--;

        }
        int left = 0;
        int right = n - 1;
        while (left < right)
        {
            if (arr[left] < arr[right])
            {
                right--;
            }
            else
            {
                left++;
            }

        }
        if (arr[left] > arr[right])
        {
            printf("%d", arr[right]);
        }
        else
        {
            printf("%d", arr[left]);
        }

    }
    return 0;
}